package com.example.hotelback.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.hotelback.entity.Reservation;
import com.example.hotelback.entity.Room;
import com.example.hotelback.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation>{

    @Select("select * from reservation where isDelete = 0")
    @Results(
            {
                    @Result(column = "id", property = "id"),
                    @Result(column = "uid", property = "uid"),
                    @Result(column = "rid", property = "rid"),
                    @Result(column = "bookingTime", property = "bookingTime"),
                    @Result(column = "leavingTime", property = "leavingTime"),
                    @Result(column = "uid", property = "user", javaType = User.class,
                        one = @One(select = "com.example.hotelback.mapper.UserMapper.selectOneById")
                    ),
                    @Result(column = "rid", property = "room", javaType = Room.class,
                        one = @One(select = "com.example.hotelback.mapper.RoomMapper.selectOneById")
                    )
            }
    )
    IPage<Reservation> selectAllReservationWithPagination(Page<Reservation> page);

    @Select("select * from reservation where uid = #{uid} and isDelete = 0")
    @Results(
            {
                    @Result(column = "id", property = "id"),
                    @Result(column = "uid", property = "uid"),
                    @Result(column = "rid", property = "rid"),
                    @Result(column = "bookingTime", property = "bookingTime"),
                    @Result(column = "leavingTime", property = "leavingTime"),
                    @Result(column = "uid", property = "user", javaType = User.class,
                            one = @One(select = "com.example.hotelback.mapper.UserMapper.selectOneById")
                    ),
                    @Result(column = "rid", property = "room", javaType = Room.class,
                            one = @One(select = "com.example.hotelback.mapper.RoomMapper.selectOneById")
                    )
            }
    )
    List<Reservation> selectPersonalReservations(int uid);
}
